﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace BlogApp.WP8.Utils
{
    public class BoolToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo language)
        {
            if (parameter is string && ((string)parameter).Equals("reverse", StringComparison.CurrentCultureIgnoreCase))
                return !(value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed;
            else
                return (value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo language)
        {
            return value is Visibility && (Visibility)value == Visibility.Visible;
        }
    }
}